@extends('layouts.admin')

@section('title', '学生学籍管理-添加')

@section('content')
    <div id="tab_student" class="HuiTab">
        <div class="tabBar clearfix"><span>基本资料</span><span>学生简历</span><span>学籍变更记录</span></div>
        <div class="tabCon">
            <article class="page-container">
                <form action="" method="post" class="form form-horizontal" id="form-techValue-add">
                    <input type="hidden" name="id" value="{{$editEntity['data']['id']}}"/>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>姓名：</label>
                        <div class="formControls col-xs-8 col-sm-9">
                            <input type="text" class="input-text" value="{{$editEntity['data']['name']}}" placeholder="" id="name" name="name">
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3"><span class="c-red"></span>曾用名：</label>
                        <div class="formControls col-xs-8 col-sm-9">
                            <input type="text" class="input-text" value="{{$editEntity['data']['old_name']}}" placeholder="" id="old_name" name="old_name">
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>学籍号：</label>
                        <div class="formControls col-xs-8 col-sm-9">
                            <input type="text" class="input-text" value="{{$editEntity['data']['census_no']}}" placeholder="" id="census_no" name="census_no">
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>名族：</label>
                        <div class="formControls col-xs-8 col-sm-9">
                            <input type="text" class="input-text" value="{{$editEntity['data']['nation']}}" placeholder="" id="nation" name="nation">
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>出生日期：</label>
                        <div class="formControls col-xs-8 col-sm-9">
                            <div class="row" style="margin-top:0;">
                                <div class="col-xs-4 col-sm-3">
                                    <input type="text" onfocus="WdatePicker()" value="{{$editEntity['data']['born_date']}}" id="born_date" name="born_date" class="input-text Wdate">
                                </div>
                                <div class="col-xs-4 col-sm-3">
                            <span class="select-box">
                                <select class="select" size="1"  id="sex" name="sex">
                                    <option value="F">女</option>
                                    <option value="M">男</option>
                                </select>
                            </span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>身份证号：</label>
                        <div class="formControls col-xs-8 col-sm-9">
                            <input type="text" class="input-text" value="{{$editEntity['data']['id_card']}}" placeholder="" id="id_card" name="id_card">
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>户籍地：</label>
                        <div class="formControls col-xs-8 col-sm-9">
                            <input type="text" class="input-text" value="{{$editEntity['data']['hometown']}}" placeholder="" id="hometown" name="hometown">
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>国籍：</label>
                        <div class="formControls col-xs-8 col-sm-9">
                            <input type="text" class="input-text" value="{{$editEntity['data']['citizenship']}}" placeholder="" id="citizenship" name="citizenship">
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>家住地址：</label>
                        <div class="formControls col-xs-8 col-sm-9">
                            <input type="text" class="input-text" value="{{$editEntity['data']['home_address']}}" placeholder="" id="home_address" name="home_address">
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>现住地址：</label>
                        <div class="formControls col-xs-8 col-sm-9">
                            <input type="text" class="input-text" value="{{$editEntity['data']['now_address']}}" placeholder="" id="now_address" name="now_address">
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>其他：</label>
                        <div class="formControls col-xs-8 col-sm-9">
                            <div class="skin-minimal">
                                <div class="check-box">
                                    <input type="checkbox" id="is_macao_or_taiwan" name="is_macao_or_taiwan" value="1">
                                    <label for="is_macao_or_taiwan">是否港澳台外</label>
                                </div>
                                <div class="check-box">
                                    <input type="checkbox" id="is_only_child" name="is_only_child" value="1">
                                    <label for="is_only_child">是否独生子女</label>
                                </div>
                                <div class="check-box">
                                    <input type="checkbox" id="is_lodge" name="is_lodge" value="1">
                                    <label for="is_lodge">是否寄宿</label>
                                </div>
                                <div class="check-box">
                                    <input type="checkbox" id="is_learn_preschool" name="is_learn_preschool" value="1">
                                    <label for="is_learn_preschool">是否受过学前教育</label>
                                </div>
                                <div class="check-box">
                                    <input type="checkbox" id="is_leftover_child" name="is_leftover_child" value="1">
                                    <label for="is_leftover_child">是否留守儿童</label>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row cl">
                        <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                            <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                        </div>
                    </div>
                </form>
            </article>
        </div>
        <div class="tabCon">
            <article class="page-container">
                <table id="listResumeTable" class="table table-border table-bordered table-bg table-hover">
                    <thead>
                    <tr class="text-c">
                        <th><input type="checkbox" name="checkResumeList"/></th>
                        <th>开始时间</th>
                        <th>结束时间</th>
                        <th>学习单位</th>
                        <th>学习内容</th>
                        <th>职位</th>
                        <th>证明人</th>
                    </tr>
                    </thead>
                </table>
            </article>
        </div>
        <div class="tabCon">
            <article class="page-container">
                <table id="listSchoolCensusTable" class="table table-border table-bordered table-bg table-hover">
                    <thead>
                    <tr class="text-c">
                        <th><input type="checkbox" name="checkSchoolCensusList"/></th>
                        <th>变更时间</th>
                        <th>变更前学籍</th>
                        <th>变更后学籍</th>
                    </tr>
                    </thead>
                </table>
            </article>
        </div>
    </div>

@endsection
@section('script')
    <script>
        $(".input-text,.textarea").Huifocusblur();
        $("#tab_student").Huitab();
        $("#sex").val('{{$editEntity['data']['sex']}}');
        $("#is_macao_or_taiwan[value={{$editEntity['data']['is_macao_or_taiwan']}}]").attr('checked','true');
        $("#is_only_child[value={{$editEntity['data']['is_only_child']}}]").attr('checked','true');
        $("#is_lodge[value={{$editEntity['data']['is_lodge']}}]").attr('checked','true');
        $("#is_learn_preschool[value={{$editEntity['data']['is_learn_preschool']}}]").attr('checked','true');
        $("#is_leftover_child[value={{$editEntity['data']['is_leftover_child']}}]").attr('checked','true');
        $("#form-techValue-add").validate({
            rules:{
                name:{
                    required:true
                },
                census_no:{
                    required:true,
                },
                nation:{
                    required:true,
                },
                born_date:{
                    required:true,
                },
                id_card:{
                    required:true,
                },
                hometown:{
                    required:true,
                },
                citizenship:{
                    required:true,
                },
                home_address:{
                    required:true,
                },
                now_address:{
                    required:true,
                },
            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                $(form).ajaxSubmit({
                    type: 'post',
                    url: "{{url('student/student/edit')}}",
                    success: function(data){
                        if(data['successFlag']==1){
                            layer_success_message("编辑成功!");
                            setTimeout(function(){
                                parent.$(".btnSearch").click();
                                layer_close();
                            },500);
                        }else{
                            layer_error_message(data['msg']);
                        }
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer_error_message('编辑失败!');
                    }
                });
            }
        });
    </script>

    <script>
        var $ResumeDataTable=null;
        var $RESUME_MAIN={currentPage:1}
        $(function(){
            $ResumeDataTable=$('#listResumeTable').dataTable({
                "sPaginationType" : "full_numbers",
                "processing": true,
                "serverSide": true,
                "searching": false,
                'ordering':false,
                "dom": '<l<\'#topStudyPlugin\'>f>rt<ip><"clear">',
                "ajax":{
                    "url":"{{url('student/resume/list')}}",
                    "type": 'post',
                    "data": function ( d ) {
                        d.page=$RESUME_MAIN.currentPage;
                        d.student_id='{{$editEntity['data']['id']}}';
                    },
                    'dataSrc':function(result){
                        var datas=result.data;
                        if(datas){
                            for(var i=0;i<datas.length;i++){
                                datas[i].DT_RowClass='text-c';
                            }
                        }
                        return datas;
                    }
                },
                "columnDefs": [{
                    "targets": "_all",
                    "searchable":false
                }],
                "columns": [
                    {
                        "data": "id",
                        "render": function (data, type, row, meta) {
                            return '<input type="checkbox"  name="checkResumeList" class="checkchild"  value="' + data + '" />';
                        }
                    },
                    { "data": "start_date"},
                    { "data": "end_date"},
                    { "data": "organization" },
                    { "data": "content" },
                    { "data": "title" },
                    { "data": "certifier" },
                ],
                drawCallback: function( settings ) {
                    $('input[name=checkResumeList]')[0].checked=false;
                },
                "initComplete":function(settings, json){
                    var topPlugin='<button class="btn btn-danger radius resumeDelSelectBtn"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</button> ' +
                        '<button class="btn btn-primary radius resumeAddBtn" ><i class="Hui-iconfont">&#xe600;</i>新增</button>';
                    $("#topStudyPlugin").append(topPlugin);
                }
            });
            $ResumeDataTable.on( 'page.dt', function () {
                var info = $ResumeDataTable.api();
                $RESUME_MAIN.currentPage=parseInt(info.page())+1;
            } );
        });

        $RESUME_MAIN.deleteDatas=function(ids){
            layer.confirm('确定要删除选择的学生简历吗？',{
                    btn: ['确定','取消'],
                    shade: false,
                    closeBtn: 0
                },
                function(){
                    $.ajax({
                        url: "{{url('student/resume/delete')}}",
                        data:{ids:ids},
                        dataType: 'json',
                        success: function(data){
                            if(data['successFlag']==1){
                                layer_success_message('删除成功!');
                                $ResumeDataTable.api().ajax.reload();
                            }else{
                                layer_error_message(data['msg']);
                            }
                        },
                        error:function(data) {
                            layer_error_message('删除失败!');
                        },
                    });
                });
        }

        $RESUME_MAIN.getSelectCheckBoxValue=function(){
            var theArray=[];
            $("input[name=checkResumeList]:checked").each(function() {
                theArray.push($(this).val());
            });
            return theArray;
        }
        $(function(){
            $(document).on("click",".resumeDelSelectBtn",function(){
                var ids=$RESUME_MAIN.getSelectCheckBoxValue();
                if(ids.length<=0){
                    layer.msg('请选择需要删除的学生简历', {icon:5,time:1000});
                }else{
                    $RESUME_MAIN.deleteDatas(ids);
                }
            });
            $(document).on("click",".resumeAddBtn",function(){
                layer_show('添加学生简历','{{url('student/resume/add')}}?student_id={{$editEntity['data']['id']}}',800,500);
            });
        })
    </script>

    <script>
        var $SchoolCensusDataTable=null;
        var $SCHOOLCENSUS_MAIN={currentPage:1}
        $(function(){
            $SchoolCensusDataTable=$('#listSchoolCensusTable').dataTable({
                "sPaginationType" : "full_numbers",
                "processing": true,
                "serverSide": true,
                "searching": false,
                'ordering':false,
                "dom": '<l<\'#topPlugin\'>f>rt<ip><"clear">',
                "ajax":{
                    "url":"{{url('student/schoolCensus/list')}}",
                    "type": 'post',
                    "data": function ( d ) {
                        d.page=$SCHOOLCENSUS_MAIN.currentPage;
                        d.student_id='{{$editEntity['data']['id']}}';
                    },
                    'dataSrc':function(result){
                        var datas=result.data;
                        if(datas){
                            for(var i=0;i<datas.length;i++){
                                datas[i].DT_RowClass='text-c';
                            }
                        }
                        return datas;
                    }
                },
                "columnDefs": [{
                    "targets": "_all",
                    "searchable":false
                }],
                "columns": [
                    {
                        "data": "id",
                        "render": function (data, type, row, meta) {
                            return '<input type="checkbox"  name="checkSchoolCensusList" class="checkchild"  value="' + data + '" />';
                        }
                    },
                    { "data": "change_date"},
                    { "data": "before_change"},
                    { "data": "after_change" },

                ],
                drawCallback: function( settings ) {
                    $('input[name=checkSchoolCensusList]')[0].checked=false;
                },
                "initComplete":function(settings, json){
                    var topPlugin='<button class="btn btn-danger radius schoolCensusDelSelectBtn"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</button> ' +
                        '<button class="btn btn-primary radius schoolCensusAddBtn" ><i class="Hui-iconfont">&#xe600;</i>新增</button>';
                    $("#topPlugin").append(topPlugin);
                }
            });
            $SchoolCensusDataTable.on( 'page.dt', function () {
                var info = $SchoolCensusDataTable.api();
                $SCHOOLCENSUS_MAIN.currentPage=parseInt(info.page())+1;
            } );
        });

        $SCHOOLCENSUS_MAIN.deleteDatas=function(ids){
            layer.confirm('确定要删除选择的学籍变更吗？',{
                    btn: ['确定','取消'],
                    shade: false,
                    closeBtn: 0
                },
                function(){
                    $.ajax({
                        url: "{{url('student/schoolCensus/delete')}}",
                        data:{ids:ids},
                        dataType: 'json',
                        success: function(data){
                            if(data['successFlag']==1){
                                layer_success_message('删除成功!');
                                $SchoolCensusDataTable.api().ajax.reload();
                            }else{
                                layer_error_message(data['msg']);
                            }
                        },
                        error:function(data) {
                            layer_error_message('删除失败!');
                        },
                    });
                });
        }

        $SCHOOLCENSUS_MAIN.getSelectCheckBoxValue=function(){
            var theArray=[];
            $("input[name=checkSchoolCensusList]:checked").each(function() {
                theArray.push($(this).val());
            });
            return theArray;
        }
        $(function(){
            $(document).on("click",".schoolCensusDelSelectBtn",function(){
                var ids=$SCHOOLCENSUS_MAIN.getSelectCheckBoxValue();
                if(ids.length<=0){
                    layer.msg('请选择需要删除的学籍变更', {icon:5,time:1000});
                }else{
                    $SCHOOLCENSUS_MAIN.deleteDatas(ids);
                }
            });
            $(document).on("click",".schoolCensusAddBtn",function(){
                layer_show('添加学籍变更','{{url('student/schoolCensus/add')}}?student_id={{$editEntity['data']['id']}}',800,500);
            });
        })
    </script>
@endsection